//
//  MMGVideoPrizeClawView.m
//  MyApp
//
//  Created by Don on 2017/9/4.
//  Copyright © 2017年 com.memego. All rights reserved.
//

#import "MMGVideoPrizeClawView.h"
#import "MMGPrizeClawOpenGLView.h"
#import "MMGJoyStickView.h"
#import "UIColor+HexColor.h"
#import "MMGVideoPrizeClawViewModel.h"
#import "UIImage+CacheViaName.h"
#import "MMGLoadingButton.h"

#import "MMGPurchasesAlert.h"

//static const float MMG_BottomContainer_Height = 250;
//static const float MMG_BottomColorContainer_Height = 180;
@interface MMGVideoPrizeClawView ()<MMGJoyStickViewDelegate>

@property (nonatomic, strong) MMGVideoPrizeClawViewModel *viewModel;
@property (nonatomic, strong) MMGPrizeClawOpenGLView *prizeClawGLView;

@property (nonatomic, strong) MMGJoyStickView *joyStick;
@property (nonatomic, strong) UIButton *prizeClawButton;
@property (nonatomic, strong) MMGLoadingButton *orderGameButton;
@property (nonatomic, strong) MMGLoadingButton *startGameButton;

@property (nonatomic, strong) UIView *counterContainer;
@property (nonatomic, strong) UIImageView *gameTimeCountDownImageView;
@property (nonatomic, strong) UILabel *gameTimeCountDownLabel;

@property (nonatomic, strong) UIButton *camChannelSwitchButton;

@property (nonatomic, strong) UIView *bottomContainer;
@property (nonatomic, strong) UIView *bottomColorBackgroundView;


//游戏参数
@property (nonatomic, strong) UIView *gameRoomStatusContainer;
@property (nonatomic, strong) UIButton *gamePerRoundCostButton;
@property (nonatomic, strong) UIButton *gameViewerButton;
@property (nonatomic, strong) UIButton *gameOrderNumButton;
//金币充值
@property (nonatomic, strong) UIButton *currentRemaindCoinButton;
@property (nonatomic, strong) UIButton *addCoinButton;

@property (nonatomic, strong) MMGPurchasesAlert *purchasesAlert;

@end
@implementation MMGVideoPrizeClawView

- (instancetype)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        [self setupUI];
    }
    return self;
}
- (void)dealloc {
    DLog(@"%@ dealloc", NSStringFromClass([self class]));
}

- (void)setupUI {
    
    self.backgroundColor = [UIColor blackColor];
    
    [self.joyStick setJSBallWithImageName:@"prize_claw_joystick_ball.png"];
    [self.joyStick setJSDockWithImageName:@"prize_claw_joystick_dock.png"];
    [self.joyStick setHitAreaWithRadius:88];
    
    CGFloat glvDefaultHeight = 240;
    if (kDeviceIsiPhone6Screen) {
        glvDefaultHeight = 281;
    }else if (kDeviceIsiPhone6PlusScreen || kDeviceIsiPhoneXScreen) {
        glvDefaultHeight = 310;
    }
    
    [self.prizeClawGLView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.mas_top);
        make.size.mas_equalTo(CGSizeMake(CGRectGetWidth(self.bounds), glvDefaultHeight));
        make.left.right.mas_equalTo(self);
    }];
    [self.camChannelSwitchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.prizeClawGLView.mas_bottom).offset(-20);
        make.right.mas_equalTo(self.prizeClawGLView.mas_right).offset(-20);
        make.size.mas_equalTo(CGSizeMake(54, 54));
    }];
    
    //房间游戏参数
    [self.gameRoomStatusContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self);
        make.top.mas_equalTo(self.prizeClawGLView.mas_bottom);
        make.height.mas_equalTo(56);
    }];
    [self.gamePerRoundCostButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(10);
        make.centerY.mas_equalTo(self.gameRoomStatusContainer.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(82, 28));
    }];
    [self.gameViewerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.gameRoomStatusContainer.mas_centerY).offset(-4);
        make.centerX.mas_equalTo(self.gameRoomStatusContainer.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(90, 16));
    }];
    [self.gameOrderNumButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gameRoomStatusContainer.mas_centerY).offset(4);
        make.centerX.mas_equalTo(self.gameRoomStatusContainer.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(90, 16));
    }];
    
    
    [self.counterContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.gamePerRoundCostButton.mas_centerY);
        make.right.mas_equalTo(self.mas_right).offset(-10);
        make.size.mas_equalTo(CGSizeMake(74, 30));
    }];
    [self.gameTimeCountDownImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.counterContainer.mas_left).offset(8);
        make.centerY.mas_equalTo(self.counterContainer.mas_centerY);
        make.size.mas_equalTo(self.gameTimeCountDownImageView.frame.size);
    }];
    [self.gameTimeCountDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.counterContainer.mas_centerY);
        make.left.mas_equalTo(self.gameTimeCountDownImageView.mas_right).offset(8);
        make.right.mas_equalTo(self.counterContainer.mas_right);
        make.height.mas_equalTo(30);
    }];
    
    
    
    [self.joyStick mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bottomContainer.mas_centerY);
        make.size.mas_equalTo(self.joyStick.frame.size);
        make.left.mas_equalTo(self.bottomContainer.mas_left).offset(20);
    }];
    
    [self.bottomContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self);
        make.bottom.mas_equalTo(self.mas_bottom);
        make.top.mas_equalTo(self.gameRoomStatusContainer.mas_bottom);
    }];
    
    [self.bottomColorBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.bottomContainer);
        make.top.bottom.mas_equalTo(self.bottomContainer);
    }];
    
    //
    [self.prizeClawButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bottomColorBackgroundView.mas_right).offset(-20);
        make.centerY.mas_equalTo(self.bottomContainer.mas_centerY);
        make.size.mas_equalTo(self.prizeClawButton.bounds.size);
    }];
    
    [self.orderGameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bottomContainer.mas_right).offset(-20);
        make.centerY.mas_equalTo(self.bottomContainer.mas_centerY);
        make.size.mas_equalTo(self.orderGameButton.bounds.size);
        
    }];
    
    [self.startGameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bottomColorBackgroundView.mas_right).offset(-20);
        make.centerY.mas_equalTo(self.bottomContainer.mas_centerY);
        make.size.mas_equalTo(self.startGameButton.bounds.size);
    }];
    
    [self.currentRemaindCoinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bottomContainer.mas_left).offset(15);
        make.centerY.mas_equalTo(self.bottomContainer.mas_centerY).offset(-23);
        make.size.mas_equalTo(CGSizeMake(148, 38));
    }];
    [self.addCoinButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bottomContainer.mas_left).offset(15);
        make.top.mas_equalTo(self.currentRemaindCoinButton.mas_bottom).offset(8);
        make.size.mas_equalTo(CGSizeMake(148, 38));
    }];
    
//    self.orderGameButton.enabled = NO;
    self.startGameButton.enabled = NO;
    self.orderGameButton.hidden = YES;//预约按钮暂时已经屏蔽，无用
    self.joyStick.hidden = self.prizeClawButton.hidden = YES;
    
    
    MMGWeakSelf(weakSelf);
    [[self.addCoinButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        dispatch_async(dispatch_get_main_queue(), ^{
//            if ([[MMGGameSYSSettings sharedMMGGameSYSSettings] appIsReviewing]) {
//                 [weakSelf.purchasesAlert show];
//            }else
            {
                [[NSNotificationCenter defaultCenter] postNotificationName:(NSNotificationName)kInAppPurchaseTransactionReceiptNotification object:@"USER_RECHARGE"];
            }
        });
    }];
    
    [RACObserve(self.startGameButton, hidden) subscribeNext:^(id  _Nullable x) {
        [weakSelf.viewModel.gameStartSignal sendNext:x];
    }];
//    [RACObserve(self.startGameButton, hidden) subscribeNext:^(id  _Nullable x) {
//        [weakSelf.viewModel.gameStartSignal sendNext:@(![x boolValue])];
//    }];
    
    
    //
//    self.addCoinButton.hidden = YES;
}

- (void)renderGL:(uint8_t *)frame videoWidth:(float)vWidth videoHeight:(float)vHeight screenWidth:(float)sWidth screenHeight:(float)sHeight {
    if (self && self.prizeClawGLView) {
        [self.prizeClawGLView renderGLWithFrame:frame videoWidth:vWidth videoHeight:vHeight screenWidth:sWidth screenHeight:sHeight];
    }
    
}

- (void)bindDataWithViewModel:(MMGBaseViewModel *)viewModel {
    self.viewModel = (MMGVideoPrizeClawViewModel *)viewModel;
    self.viewModel.glContextIsReadySignal = self.prizeClawGLView.glContentCreateSignal;
    
    MMGWeakSelf(weakSelf);
    [RACObserve(self.viewModel, glViewHeight) subscribeNext:^(id  _Nullable x) {
        if ([x intValue] <= 0) {
            return ;
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.prizeClawGLView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(weakSelf.mas_top);
                make.size.mas_equalTo(CGSizeMake(CGRectGetWidth(weakSelf.bounds), [x intValue]));
                make.left.right.mas_equalTo(weakSelf);
            }];
            [weakSelf.prizeClawGLView setNeedsLayout];
            [weakSelf.prizeClawGLView layoutIfNeeded];
        });
        
    }];
    
    [self.viewModel.onGameStateDidChageSignal subscribeNext:^(id  _Nullable x) {
        dispatch_async(dispatch_get_main_queue(), ^{
            
            switch ([x intValue]) {
                case EMMMGVideoPrizeClawViewStateStartGame:
                {
                    //激活开始游戏按钮
//
//                    weakSelf.startGameButton.hidden = YES;
//                    //                    weakSelf.startGameButton.hidden = NO;
//                    //                    weakSelf.startGameButton.enabled = YES;
//                    weakSelf.currentRemaindCoinButton.hidden =weakSelf.addCoinButton.hidden = NO;
//                    weakSelf.joyStick.hidden = weakSelf.prizeClawButton.hidden  = YES;
                    
                    UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_start_game_icon.png"];
                    [weakSelf.startGameButton setImage:image forState:UIControlStateNormal];
                    weakSelf.startGameButton.enabled = YES;
                    weakSelf.startGameButton.hidden = NO;
                    //                    weakSelf.startGameButton.hidden = YES;
                    weakSelf.joyStick.hidden = weakSelf.prizeClawButton.hidden = YES;
                    weakSelf.currentRemaindCoinButton.hidden =weakSelf.addCoinButton.hidden = NO;
                }
                    break;
                case EMMMGVideoPrizeClawViewStateJoystick:{
                    
                    weakSelf.startGameButton.hidden =  YES;
                    weakSelf.prizeClawButton.enabled = YES;
                    weakSelf.joyStick.hidden = weakSelf.prizeClawButton.hidden = NO;
                    weakSelf.currentRemaindCoinButton.hidden =weakSelf.addCoinButton.hidden = YES;
                    
                }
                    break;
                case EMMMGVideoPrizeClawViewStateOrderGame: {
                    UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_waiting_game_icon.png"];
                    [weakSelf.startGameButton setImage:image forState:UIControlStateNormal];
                    weakSelf.startGameButton.enabled = NO;
                    weakSelf.startGameButton.hidden = NO;
                    //                    weakSelf.startGameButton.hidden = YES;
                    weakSelf.joyStick.hidden = weakSelf.prizeClawButton.hidden = YES;
                    weakSelf.currentRemaindCoinButton.hidden =weakSelf.addCoinButton.hidden = NO;
                }
                    break;
                case EMMMGVideoPrizeClawViewStateClawAck: {
                    weakSelf.prizeClawButton.enabled = NO;
                }
                    break;
                    
                default: {
                    UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_start_game_icon.png"];
                    [weakSelf.startGameButton setImage:image forState:UIControlStateNormal];
                    weakSelf.startGameButton.enabled = YES;
                    weakSelf.startGameButton.hidden = NO;
                    //                    weakSelf.startGameButton.hidden = YES;
                    weakSelf.joyStick.hidden = weakSelf.prizeClawButton.hidden = YES;
                    weakSelf.currentRemaindCoinButton.hidden =weakSelf.addCoinButton.hidden = NO;
                }
                    break;
            }
        });

    }];
    
//    //用户当前余额
//    @property(nonatomic,assign) int userRemaindCost;
//    //观看人数
//    @property(nonatomic,assign) int visiteCount;
//    //预约人数
//    @property(nonatomic,assign) int reserveCount;
//    //当前机器的游戏状态
//    @property(nonatomic,assign) NSString *gameCurrentStatus;
    [self.gamePerRoundCostButton setTitle:[NSString stringWithFormat:@"1局 %d 金币",self.viewModel.perRoundCostCoin] forState:UIControlStateNormal];
    
    [RACObserve(self, self.viewModel.userRemaindCoin) subscribeNext:^(NSNumber*  _Nullable coins) {
        dispatch_async(dispatch_get_main_queue(), ^{
            int userCoin = [coins intValue];
            [weakSelf.currentRemaindCoinButton setTitle:[NSString stringWithFormat:@"我的金币: %d",userCoin] forState:UIControlStateNormal];
        });
        
    }];
    [RACObserve(self, self.viewModel.visiteCount) subscribeNext:^(NSNumber*  _Nullable viwersCount) {
        dispatch_async(dispatch_get_main_queue(), ^{
            int visitorCount = [viwersCount intValue];
            [weakSelf.gameViewerButton setTitle:[NSString stringWithFormat:@"观看人数 %d",visitorCount] forState:UIControlStateNormal];
        });
        
    }];
    [RACObserve(self, self.viewModel.reserveCount) subscribeNext:^(NSNumber*  _Nullable reserveCount) {
        
        dispatch_async(dispatch_get_main_queue(), ^{
            int count = [reserveCount intValue];
            [weakSelf.gameOrderNumButton setTitle:[NSString stringWithFormat:@"预约人数 %d",count] forState:UIControlStateNormal];
        });
        
    }];
    
    //倒计时
    [RACObserve(self, self.viewModel.gameTimeOut) subscribeNext:^(NSNumber*  _Nullable timeOut) {
        int limitTime = [timeOut intValue];
        //
        if (limitTime != 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                weakSelf.gameTimeCountDownLabel.text = [NSString stringWithFormat:@"%d",limitTime];
             });
            [weakSelf.viewModel startCountDownWithTimeSec:limitTime counting:^(int time) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    weakSelf.gameTimeCountDownLabel.text = [NSString stringWithFormat:@"%d",time];
                });
                
            } overCount:^(int time) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    weakSelf.gameTimeCountDownLabel.text = [NSString stringWithFormat:@"%d",time];
                });
            }];
        }
        
    }];
    
    [RACObserve(self.viewModel, dismissIAPAlert) subscribeNext:^(id  _Nullable x) {
        if ([x boolValue]) {
            [weakSelf.purchasesAlert dismissAlert];
        }
    }];
    
}


//TODO: - GAME CONTROL
- (void)orderGame:(UIButton *)button {
    button.enabled = NO;
    if (button == self.startGameButton) {
        UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_waiting_game_icon.png"];
        [self.startGameButton setImage:image forState:UIControlStateNormal];
        
        [self.viewModel sendGameReserveMsg];
    }
//    else {
//
//        [self.viewModel sendGameStartMsg:@"0"];//服务器后面修改了，发送开始游戏不需要限制时间参数
//    }
}

//TODO: - CAM SWITCH
- (void)camSwitch:(UIButton *)button {
    
    if (self.viewModel.cameraChannel < (kMMG_CAMERA_MAXMUM - 1)) {
        self.viewModel.cameraChannel += 1;
    }else {
        self.viewModel.cameraChannel = 0;
    }
    
    
    
}

//TODO: -CLAW PRIZE
- (void)clawPrize:(UIButton *)button {
    self.joyStick.userInteractionEnabled = self.prizeClawButton.enabled = NO;
    [self.viewModel sendStartClawMsg];
    
    [self.viewModel stopCountDown];
    //下爪后开始计算超时，以便于防止服务器没有任何结果返回导致一直停留在游戏页面的BUG
    [self.viewModel startCountDownWithTimeSec:15 counting:^(int time) {
        
    } overCount:^(int time) {
        [self.viewModel.timeOut2CloseSignal sendNext:@(time)];
    }];
}

#pragma mark - joystick delegate
- (void)onMMGJoyStickActivated:(MMGJoyStickView *)joyStick {}
- (void)onMMGJoyStickDeactivated:(MMGJoyStickView *)joyStick {}
- (void)onMMGJoyStickUpdate:(MMGJoyStickView *)joyStick radian:(float)radian directionPoint:(CGPoint)point power:(float)power {
    DLog(@"----------------------");
    //    DLog(@"joystick: %@ , angle: %f  , directionP:%@ , power :%f",joyStick,radian,NSStringFromCGPoint(point),power);
    [self.viewModel sendPrizeClawMachineControlMsgWith:radian];
}

#pragma lazy init
- (MMGPrizeClawOpenGLView *)prizeClawGLView {
    if (!_prizeClawGLView) {
        _prizeClawGLView = [[MMGPrizeClawOpenGLView alloc] initWithFrame:CGRectZero];
        [self insertSubview:_prizeClawGLView belowSubview:self.bottomContainer];
    }
    
    return _prizeClawGLView;
}

- (MMGJoyStickView *)joyStick {
    if (!_joyStick) {
        _joyStick = [[MMGJoyStickView alloc] initJoyStickWithFrame:CGRectMake(20, 20, 150, 150) moveAreaRadius:50 followTouch:NO canVisible:YES autoHide:NO animation:YES];
        _joyStick.delegate = self;
        _joyStick.backgroundColor = [UIColor clearColor];
        [self.bottomContainer insertSubview:_joyStick aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _joyStick;
}

- (UIButton *)prizeClawButton {
    if (!_prizeClawButton) {
        _prizeClawButton = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_claw_icon.png"];
        [_prizeClawButton setImage:image forState:UIControlStateNormal];
        [_prizeClawButton addTarget:self action:@selector(clawPrize:) forControlEvents:UIControlEventTouchUpInside];
        _prizeClawButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        
        [self.bottomContainer insertSubview:_prizeClawButton aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _prizeClawButton;
}

- (MMGLoadingButton *)orderGameButton {
    if (!_orderGameButton) {
        _orderGameButton = [MMGLoadingButton buttonWithType:UIButtonTypeCustom];
        UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_order_game_icon.png"];
        [_orderGameButton setImage:image forState:UIControlStateNormal];
        [_orderGameButton addTarget:self action:@selector(orderGame:) forControlEvents:UIControlEventTouchUpInside];
        _orderGameButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        
        [self.bottomContainer insertSubview:_orderGameButton aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _orderGameButton;
}

- (MMGLoadingButton *)startGameButton {
    if (!_startGameButton) {
        _startGameButton = [MMGLoadingButton buttonWithType:UIButtonTypeCustom];
        UIImage *image = [UIImage mmg_imageNamed:@"prize_claw_start_game_icon.png"];
        [_startGameButton setImage:image forState:UIControlStateNormal];
        [_startGameButton addTarget:self action:@selector(orderGame:) forControlEvents:UIControlEventTouchUpInside];
        _startGameButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        
        [self.bottomContainer insertSubview:_startGameButton aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _startGameButton;
}
- (UIButton *)camChannelSwitchButton {
    if (!_camChannelSwitchButton) {
        _camChannelSwitchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        UIImage *image = [UIImage mmg_imageNamed:@"prize_clam_camera_switch.png"];
        [_camChannelSwitchButton setImage:image forState:UIControlStateNormal];
        [_camChannelSwitchButton addTarget:self action:@selector(camSwitch:) forControlEvents:UIControlEventTouchUpInside];
        
        [self insertSubview:_camChannelSwitchButton aboveSubview:self.prizeClawGLView];
        
    }
    return _camChannelSwitchButton;
}

- (UIView *)bottomContainer {
    if (!_bottomContainer) {
        _bottomContainer = [[UIView alloc] init];
        
        _bottomContainer.backgroundColor = [UIColor clearColor];
        [self addSubview:_bottomContainer];
    }
    return _bottomContainer;
}

- (UIView *)bottomColorBackgroundView {
    if (!_bottomColorBackgroundView) {
        _bottomColorBackgroundView = [[UIView alloc] init];
        _bottomColorBackgroundView.backgroundColor = [UIColor mmg_colorWithHex:kMMGColorHex_MainColor];
        
        [self.bottomContainer addSubview:_bottomColorBackgroundView];
    }
    return _bottomColorBackgroundView;
}

- (UIView *)counterContainer {
    if (!_counterContainer) {
        _counterContainer = [[UIView alloc] init];
        _counterContainer.backgroundColor = [UIColor mmg_colorWithHex:kMMGColorHex_GameCountDownColor];
        _counterContainer.layer.cornerRadius = 15;
        _counterContainer.clipsToBounds = YES;
        
        [self.gameRoomStatusContainer addSubview:_counterContainer];
    }
    
    return _counterContainer;
}
- (UIImageView *)gameTimeCountDownImageView {
    
    if (!_gameTimeCountDownImageView) {
        UIImage *image = [UIImage imageNamed:@"time.png"];
        _gameTimeCountDownImageView = [[UIImageView alloc] init];
        _gameTimeCountDownImageView.image = image;
        _gameTimeCountDownImageView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
        
        [self.counterContainer addSubview:_gameTimeCountDownImageView];
    }
    
    return _gameTimeCountDownImageView;
    
}

- (UILabel *)gameTimeCountDownLabel {
    if (!_gameTimeCountDownLabel) {
        _gameTimeCountDownLabel = [[UILabel alloc] init];
        _gameTimeCountDownLabel.backgroundColor = [UIColor mmg_colorWithHex:kMMGColorHex_GameCountDownColor];
        _gameTimeCountDownLabel.text = @"--";
        _gameTimeCountDownLabel.textColor = [UIColor whiteColor];
        _gameTimeCountDownLabel.textAlignment = NSTextAlignmentLeft;
        _gameTimeCountDownLabel.font = [UIFont boldSystemFontOfSize:20];
        _gameTimeCountDownLabel.layer.cornerRadius = 15;
        _gameTimeCountDownLabel.clipsToBounds = YES;
        [self.counterContainer addSubview:_gameTimeCountDownLabel];
    }
    return _gameTimeCountDownLabel;
}


//TODO - 游戏参数
- (UIView *)gameRoomStatusContainer {
    if (!_gameRoomStatusContainer) {
        _gameRoomStatusContainer = [[UIView alloc] init];
        _gameRoomStatusContainer.backgroundColor = [UIColor mmg_colorWithHex:kMMGColorHex_GameRoomStatusContainer alpha:1];
        
        [self insertSubview:_gameRoomStatusContainer aboveSubview:self.prizeClawGLView];
    }
    
    return _gameRoomStatusContainer;
}

- (UIButton *)gamePerRoundCostButton {
    if (!_gamePerRoundCostButton) {
        _gamePerRoundCostButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _gamePerRoundCostButton.backgroundColor = [UIColor whiteColor];
        [_gamePerRoundCostButton setTitle:@"1局10金币" forState:UIControlStateNormal];
        [_gamePerRoundCostButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _gamePerRoundCostButton.titleLabel.font = [UIFont systemFontOfSize:10];
        _gamePerRoundCostButton.layer.cornerRadius = 14;
        _gamePerRoundCostButton.clipsToBounds = YES;
        _gamePerRoundCostButton.enabled = NO;
        
        UIImage *image = [UIImage mmg_imageNamed:@"icon_gold_small.png"];
        [_gamePerRoundCostButton setImage:image forState:UIControlStateDisabled];
        
        [self.gameRoomStatusContainer addSubview:_gamePerRoundCostButton];
    }
    
    return _gamePerRoundCostButton;
}

- (UIButton *)gameViewerButton {
    if (!_gameViewerButton) {
        _gameViewerButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _gameViewerButton.backgroundColor = [UIColor whiteColor];
        [_gameViewerButton setTitle:@"观看人数 --" forState:UIControlStateNormal];
        [_gameViewerButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _gameViewerButton.titleLabel.font = [UIFont systemFontOfSize:10];
        _gameViewerButton.layer.cornerRadius = 7;
        _gameViewerButton.clipsToBounds = YES;
        _gameViewerButton.enabled = NO;
        
        UIImage *image = [UIImage mmg_imageNamed:@"star_01.png"];
        [_gameViewerButton setImage:image forState:UIControlStateDisabled];
        
        [self.gameRoomStatusContainer addSubview:_gameViewerButton];
    }
    
    return _gameViewerButton;
}

- (UIButton *)gameOrderNumButton {
    if (!_gameOrderNumButton) {
        _gameOrderNumButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _gameOrderNumButton.backgroundColor = [UIColor whiteColor];
        [_gameOrderNumButton setTitle:@"预约人数 0" forState:UIControlStateNormal];
        [_gameOrderNumButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _gameOrderNumButton.titleLabel.font = [UIFont systemFontOfSize:10];
        _gameOrderNumButton.layer.cornerRadius = 7;
        _gameOrderNumButton .clipsToBounds = YES;
        _gameOrderNumButton.enabled = NO;
        
        UIImage *image = [UIImage mmg_imageNamed:@"star_02.png"];
        [_gameOrderNumButton setImage:image forState:UIControlStateDisabled];
        
        [self.gameRoomStatusContainer addSubview:_gameOrderNumButton];
    }
    
    return _gameOrderNumButton;
}

//TODO: - 金币充值
- (UIButton *)currentRemaindCoinButton {
    if (!_currentRemaindCoinButton) {
        _currentRemaindCoinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _currentRemaindCoinButton.backgroundColor = [UIColor mmg_colorWithHex:kMMGColorHex_GameRoomStatusContainer];
        [_currentRemaindCoinButton setTitle:@"我的金币: 10" forState:UIControlStateNormal];
        [_currentRemaindCoinButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _currentRemaindCoinButton.titleLabel.font = [UIFont systemFontOfSize:11];
        _currentRemaindCoinButton.layer.cornerRadius = 16;
        _currentRemaindCoinButton .clipsToBounds = YES;
        _currentRemaindCoinButton.layer.borderColor = [UIColor whiteColor].CGColor;
        _currentRemaindCoinButton.layer.borderWidth = 2;
        
        UIImage *image = [UIImage mmg_imageNamed:@"icon_glod.png"];
        [_currentRemaindCoinButton setImage:image forState:UIControlStateNormal];
        
        [self.bottomContainer insertSubview:_currentRemaindCoinButton aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _currentRemaindCoinButton;
}

- (UIButton *)addCoinButton {
    if (!_addCoinButton) {
        _addCoinButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _addCoinButton.backgroundColor = [UIColor whiteColor];
        [_addCoinButton setTitle:@"金币充值" forState:UIControlStateNormal];
        [_addCoinButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _addCoinButton.titleLabel.font = [UIFont systemFontOfSize:11];
        _addCoinButton.layer.cornerRadius = 16;
        _addCoinButton .clipsToBounds = YES;
        _addCoinButton.layer.borderColor = [UIColor whiteColor].CGColor;
        _addCoinButton.layer.borderWidth = 2;
        
        
        UIImage *image = [UIImage mmg_imageNamed:@"icon_add.png"];
        [_addCoinButton setImage:image forState:UIControlStateNormal];
        
        [self.bottomContainer insertSubview:_addCoinButton aboveSubview:self.bottomColorBackgroundView];
    }
    
    return _addCoinButton;
}

- (MMGPurchasesAlert *)purchasesAlert {
    if (!_purchasesAlert) {
        _purchasesAlert = [[MMGPurchasesAlert alloc] init];
    }
    
    return _purchasesAlert;
}


@end
